#include<iostream>
#include<string>
#include<queue>
using namespace std;
class TreeNode {
public:
	char Data;
	TreeNode* left;
	TreeNode* right;
	TreeNode(char ch = '0') {
		Data = ch;
		left = right = NULL;
	}
};
class Tree {
public:
	TreeNode* p;
	Tree(string str) {
		int len = str.length();
		p = new TreeNode;
		int m = 0;
		p = CreateTree(str, &m, str.length());
	}
	TreeNode* CreateTree(string str, int* n, int len) {
		if (*n >= len || str[*n] == '0') {
			(*n)++;
			return NULL;
		}
		TreeNode* Node = new TreeNode;
		Node->Data = str[*n];
		(*n)++;
		Node->left = CreateTree(str, n, len);
		Node->right = CreateTree(str, n, len);
		return Node;
	}
	bool is(TreeNode* p) {
		return p != NULL && p->left == NULL && p->right == NULL;
	}
	void print() {
		queue<TreeNode*>q;
		q.push(p);
		while (!q.empty()) {
			TreeNode* tmp = q.front();
			cout << tmp->Data;
			if (tmp->left != NULL) {
				q.push(tmp->left);
			}
			if (tmp->right != NULL) {
				q.push(tmp->right);
			}
			q.pop();
		}
		cout << endl;
	}
};
int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		string str;
		cin >> str;
		Tree p(str);
		p.print();
	}
	return 0;
}